package clienteServidor.infoHWSWEquipo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.win32.StdCallLibrary;

public interface Kernel32 extends StdCallLibrary{
    public Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("Kernel32", Kernel32.class);

    /**
     * @see http://msdn2.microsoft.com/en-us/library/aa373232.aspx
     */
    public class SYSTEM_POWER_STATUS extends Structure implements Serializable{
        /**
		 * 
		 */
		private static final long serialVersionUID = 1601646329260296434L;
		public byte ACLineStatus;
        public byte BatteryFlag;
        public byte BatteryLifePercent;
        public byte Reserved1;
        public int BatteryLifeTime;
        public int BatteryFullLifeTime;

        @Override
        protected List<String> getFieldOrder(){
            ArrayList<String> fields = new ArrayList<String>();
            fields.add("ACLineStatus");
            fields.add("BatteryFlag");
            fields.add("BatteryFullLifeTime");
            fields.add("BatteryLifePercent");
            fields.add("BatteryLifeTime");
            fields.add("Reserved1");
            return fields;
        }

        /**
         * The AC power status
         */
        public String getACLineStatusString(){
            switch (ACLineStatus){
                case (0): return Bateria.OFFLINE;
                case (1): return Bateria.ONLINE;
                default: return Bateria.DESCONOCIDO;
            }
        }

        /**
         * The battery charge status
         */
        public String getBatteryFlagString(){
            switch (BatteryFlag){
                case (1): return "Alta, mas del 66%";
                case (2): return "Baja, menos del 33%";
                case (4): return "Critica, menos del 5%";
                case (8): return "Cargando";
                case ((byte) 128): return "No existe bateria";
                default: return Bateria.DESCONOCIDO;
            }
        }

        /**
         * The percentage of full battery charge remaining
         */
        public String getBatteryLifePercent(){
            return (BatteryLifePercent == (byte) 255) ? Bateria.DESCONOCIDO : BatteryLifePercent + "%";
        }

        /**
         * The number of seconds of battery life remaining
         */
        public String getBatteryLifeTime(){
            return (BatteryLifeTime == -1) ? Bateria.DESCONOCIDO : BatteryLifeTime + " segundos";
        }

        /**
         * The number of seconds of battery life when at full charge
         */
        public String getBatteryFullLifeTime(){
            return (BatteryFullLifeTime == -1) ? Bateria.DESCONOCIDO : BatteryFullLifeTime + " segundos";
        }

        @Override
        public String toString(){
            StringBuilder sb = new StringBuilder();
            sb.append("ACLineStatus: " + getACLineStatusString() + "\n");
            sb.append("Battery Flag: " + getBatteryFlagString() + "\n");
            sb.append("Battery Life: " + getBatteryLifePercent() + "\n");
            sb.append("Battery Left: " + getBatteryLifeTime() + "\n");
            sb.append("Battery Full: " + getBatteryFullLifeTime() + "\n");
            return sb.toString();
        }
    }

    /**
     * Fill the structure.
     */
    public int GetSystemPowerStatus(SYSTEM_POWER_STATUS result);
}